package ubiqweb.spring3.dao;

import java.util.Date;
import java.util.List;

import ubiqweb.spring3.model.LoginDetails;
import ubiqweb.spring3.model.Registration;
import ubiqweb.spring3.model.UserDetails;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("userDao")
public class UserDaoImpl implements UserDao {

	@Autowired
	private SessionFactory sessionFactory;


	public void saveUser(Registration registration) {
		sessionFactory.getCurrentSession().saveOrUpdate(registration);
	}
	
	public void saveUserDetails(UserDetails userDetails) {
		sessionFactory.getCurrentSession().saveOrUpdate(userDetails);
	}
	
	public void saveLoginDetails( LoginDetails loginDetails ){
		sessionFactory.getCurrentSession().saveOrUpdate(loginDetails);
	}
	
	@SuppressWarnings("unchecked")
	public List<Registration> listUsers() {		
		return (List<Registration>) sessionFactory.getCurrentSession().createCriteria(Registration.class).list();
	}
	
	@SuppressWarnings("unchecked")
	public List<Registration> listUserDetails(String userId) {		
		return sessionFactory.getCurrentSession().createQuery("from Registration where userId = '" +userId + "'").list();
	}

	
	@SuppressWarnings("unchecked")
	public List<LoginDetails> listLoginDetails(String userId){
		return sessionFactory.getCurrentSession().createQuery("from LoginDetails where userId = '" +userId + "'").list();

	}
}